<template>
	<view>
		<view class="title" :style="{paddingTop:navigationBarHeight+'px',backgroundSize:'contain'}">代理商 登录</view>
		<view class="form">
			<input type="text" placeholder="请输入账号" v-model="form.loginName"/>
			<input type="password" placeholder="请输入密码" v-model="form.password"/>
			
			<view class="agreement">
				
				<u-checkbox-group v-model="isKnow">
					<u-checkbox activeColor="#e5002d" shape="circle" :name="1"></u-checkbox>
				</u-checkbox-group>
				<view>
					我已阅读并同意<text @click="toXieYi" class="shu" style="color: #FE7E4F;">《代理商隐私协议》</text>
				</view>
			</view>
		
			<button class="btn_sub" @click="login" v-if="!isKnow[0]||!form.loginName||!form.password">登录检查</button>
			<button class="btn_sub" @click="getPhone" open-type="getPhoneNumber" v-else>登录</button>
		</view>
		<!-- <login :showLogin="showLogin" @loginSuccess="loginSuccess" @cancelLogin="showLogin = false" /> -->
		<view class="zhuce">
			<view>还不是代理商</view>
			<navigator url="/pages/driver/applicationForm/index" hover-class="none">
				<image src="../../../static/ic_application.png" mode=""></image>
				代理商申请
			</navigator>
		</view>
	</view>
</template>

<script>
	import {login} from '@/api/agent.js'
	import EventBusMacro from "@/plugins/EventBus/eventBusMacro.js"
	export default{
		data(){
			return{
				navigationBarHeight:this.$store.state.device.navigationBarHeight+20,
				isKnow:[],
				// bgHeader:require('@/static/mine_header.png'),
				form:{},
				showLogin:false,
				scene: '',
			}
		},
		onLoad(options) {
			this.scene = options?.scene ? options.scene : ''
		},
		methods:{
			toXieYi(){
				uni.navigateTo({
					url:'/pages/agreement/userInfo'
				})
			},
			loginSuccess() {
				this.showLogin = false
				
				this.userInfo = this.$store.state.userInfo
				this.$events.emit(EventBusMacro.EB_LOGIN_SCUCCESS)
			
				if (this.scene === this.$TOOLS.LOGIN_SCENE.LS_HOMEPAGE_SCAN_PRIZE_AUTHORIZATION) {
					this.$events.emit(EventBusMacro.EB_HOMEPAGE_SCAN_PRIZE_AUTHORIZATION)
					this.scene = '' //复位
				}
				uni.navigateBack()
			},
			login(){
					
					if(!this.form.loginName){
						uni.showToast({
							title:'请输入账号',
							icon:'none'
						})
						return false;
					}
					if(!this.form.password){
						uni.showToast({
							title:'请输入密码',
							icon:'none'
						})
						return false;
					}
					if(!this.isKnow[0]){
						uni.showToast({
							title:'请同意隐私协议',
							icon:'none'
						})
						return false;
					}
					
			},
			getPhone(e){
				uni.login({
					success:res=>{
						login({
							code:e.detail.code,
							loginCode:res.code,
							password:this.form.password,
							loginName:this.form.loginName,
						}).then(success=>{
							
							this.$store.commit('setToken', success.authorization)
							this.$store.commit('SET_USER_INFO', success)
							this.loginSuccess()
						}).catch(err=>{
							console.log('catch',err)
							uni.showToast({
								title:err.message,
								duration:10000,
								icon:'none'
							})
						})
					},
					fail:f=>{
						console.log('登录失败',f)
						uni.showToast({
							title:'fail:'+f,
							duration:10000,
							icon:'none'
						})
					}
				})
				
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.zhuce{
		position: fixed;
		bottom: 56rpx;
		left: 0;
		font-size: 24rpx;
		color: #959595;
		text-align: center;
		width: 100%;
		
		&>navigator{
			font-size: 28rpx;
			color: #333;
			
			&>image{
				width: 94rpx;
				height: 94rpx;
				margin: 30rpx auto 4rpx;
			}
		}
		
	}
	.title{
		font-size: 64rpx;
		padding:0 40rpx 100rpx ;
		background-color: #ccc;
		height: 460rpx;
	}
	
	.form{
		background-color: #fff;
		border-radius: 40rpx;
		padding:50rpx 30rpx;
		
		margin: -60rpx auto 0;
		
		&>input{
			width: 100%;
			padding: 10rpx 20rpx;
			font-weight: bold;
			margin-bottom: 40rpx;
			border-bottom: 2rpx solid #d6d6d6;
		}
	}
	.agreement{
		display: flex;
		align-items: center;
		margin-top:76rpx;
		
		
	}
	.btn_sub{
		
		height: 90rpx;
		border-radius: 10rpx;
		background-color: #F2D621 ;
		margin: 50rpx auto;
		font-size: 34rpx;
	}
</style>